var express = require('express');
var router = express.Router();
var { userModel } =require("../model/usermodel")
var { storeModel } =require("../model/Store")
var { goodModel } =require("../model/goods");
const goods = require('../model/goods');
const { json } = require('express');

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post('/uploadImg', async (req, res) => {
  let form = new multiparty.Form()
  form.uploadDir = 'upload'
  form.parse(req, (err, formData, imgData) => {
      console.log(imgData, "111111111111111111111111111111");
      res.send({
          path: "http://localhost:6666/" + imgData.file[0].path
      })
  })
})
router.get("/store/:id",async(req,res)=>{
  let data=await storeModel.find({_id:req.params.id}).populate("userid")
  console.log(data);
  res.send(data)
})
router.get("/userhello",async(req,res)=>{
  console.log(req.query);
  let data=await userModel.find({userID:req.query.userID})
  res.send(data)
})
router.post("/addgood",async(req,res)=>{
  console.log(req.body); 
  let data=await goodModel.create(req.body)

  res.send(data)
})

module.exports = router;
